home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998…tember: Reference Library / Dev.CD Sep 98 RL1.toast / Technical Documentation / develop / develop Issue 23 / develop Issue 23 code / ProjectDrag 1.1b8.sea / ProjectDrag 1.1b8 / Sources / ProjectDrag Sources / CheckOut.c / CheckOut.c
Encoding:
C/C++ Source or Header  |  1995-09-07  |  3.6 KB  |  158 lines  |  [TEXT/MPS ]

  1. /* CheckOut.c: CheckOut applet for ProjectDrag
  2.  *
  3.  * A set of applets for drag and drop source control by Tim Maroney.
  4.  * See develop, issue 23 for details.
  5.  *
  6.  * Built on DropShell by Leonard Rosenthol, Stephan Somogyi, and Marshall Clow,
  7.  * and using the MoreFiles utilities by Jim Luther.
  8.  *
  9.  * This software is free, but don't modify and redistribute it without
  10.  * changing the status window to indicate your name and your changes!
  11.  */
  12.  
  13.  
  14. #include <Errors.h>
  15.  
  16. #include "DSUserProcs.h"
  17. #include "SourceServer.h"
  18. #include "PDDialogs.h"
  19. #include "Comments.h"
  20. #include "TasksAndErrors.h"
  21. #include "FileCancel.h"
  22.  
  23.  
  24. void CheckOutFile(FSSpec *file);
  25.  
  26.  
  27. /* This routine is called for each file passed in the ODOC event. */
  28.  
  29. pascal void OpenDoc ( FSSpecPtr myFSSPtr, Boolean opening, Handle userDataHandle )
  30. {
  31. #pragma unused ( opening )
  32. #pragma unused ( userDataHandle )
  33.  
  34.     CheckOutFile(myFSSPtr);
  35. }
  36.  
  37.  
  38. void CheckOutFile(FSSpec *file)
  39. {
  40.     Str63 userName;
  41.     Str15 nickname;
  42.     OSErr err;
  43.     CKIDHandle theCKID;
  44.     AEDesc command;
  45.     Str255 comment;
  46.     Str255 projectName;
  47.  
  48.     TaskStart(2001, 1, file->name, NULL, NULL, NULL);
  49.     
  50.     /* find the user name and initials */
  51.     err = GetUserSettings(userName, nickname, false);
  52.     if (err != noErr)
  53.     {
  54.         gDone = true;
  55.         return;
  56.     }
  57.  
  58.     /* get the CKID */
  59.     err = ExtractCKID(file, &theCKID);
  60.     if (err != noErr)
  61.     {
  62.         RaiseErrorString(kProjectDragStrings, kCantGetCKID, file->name,
  63.                          NULL, NULL, NULL);
  64.         return;
  65.     }
  66.     
  67.     /* make sure the file is checked in */
  68.     if ((*theCKID)->writeable || (*theCKID)->modifyReadOnly)
  69.     {
  70.         DisposeHandle((Handle)theCKID);
  71.         RaiseErrorString(kProjectDragStrings, kNoCheckOutPermission, file->name,
  72.                          NULL, NULL, NULL);
  73.         return;
  74.     }
  75.  
  76.     /* get the checkout comment from the user */
  77.     comment[0] = 0;
  78.     if (!GetChangeComment(false, file->name, comment))
  79.     {
  80.         DisposeHandle((Handle)theCKID);
  81.         return;
  82.     }
  83.     
  84.     /* mount the project */
  85.     err = MountProjectFromCKID(theCKID, projectName);
  86.     if (err != noErr)
  87.     {
  88.         DisposeHandle((Handle)theCKID);
  89.         return;
  90.     }
  91.     
  92.     /* create a CheckOut -m command for SourceServer
  93.      * CheckOut -m -cs <comment> -d <dir> -project <project> -u <user> <file>
  94.      */
  95.     err = CreateCommand(&command, "CheckOut");
  96.     if (err == noErr)
  97.         err = AddCStringArg(&command, "-m");
  98.     if (err == noErr)
  99.         err = AddCommentArg(&command, comment);
  100.     if (err == noErr)
  101.         err = AddDirArg(&command, file->vRefNum, file->parID);
  102.     if (err == noErr)
  103.         err = AddProjectArg(&command, projectName);
  104.     if (err == noErr)
  105.         err = AddUserArg(&command, userName);
  106.     if (err == noErr)
  107.         err = AddPStringArg(&command, file->name);
  108.     if (err != noErr)
  109.     {
  110.         DisposeHandle((Handle)theCKID);
  111.         AEDisposeDesc(&command);
  112.         RaiseErrorNumber(err);
  113.         return;
  114.     }
  115.     
  116.     err = SendCommand(&command);        /* send the command to SourceServer */
  117.     if (err != noErr)
  118.     {
  119.         DisposeHandle((Handle)theCKID);
  120.         return;
  121.     }
  122.     
  123.     /* add the checkout comment to the file */
  124.     err = AddCheckoutComment(file, userName, nickname, comment);
  125.     if (err != noErr)
  126.     {
  127.         /* pop the current task and start a new one if user confirms cancel */
  128.         if (!ResTextYesNo(kProjectDragStrings, kCheckoutCommentFailedCancel,
  129.                          file->name, NULL, NULL, NULL))
  130.         {
  131.             DisposeHandle((Handle)theCKID);
  132.             RaiseErrorNumber(userCanceledErr);
  133.             return;
  134.         }
  135.         
  136.         TaskDone(); /* not really! */
  137.         TaskStart(2001, 2, file->name, NULL, NULL, NULL);
  138.         err = FileCancel(file, theCKID);
  139.         DisposeHandle((Handle)theCKID);
  140.         if (err != noErr) return;
  141.     }
  142.     
  143.     /* modify the label to green (2) */
  144.     SetFileLabel(file, 2, NULL);
  145.     
  146.     DisposeHandle((Handle)theCKID);
  147.     TaskDone();
  148. }
  149.  
  150.  
  151. void DoFileMenu(short itemID)
  152. {
  153.     if ( itemID == 1 )
  154.         SelectFile();        // call file selection userProc
  155.     else
  156.         SendQuitToSelf();    // send self a 'quit' event
  157. }
  158.